package com.wf.messageBoard.config;

import com.wf.apicommons.config.RabbitConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Description: RabbitMQ配置类
 */
@Configuration
public class RabbitMQConfig {

    //-------------------------ES数据同步配置-------------------------------


    /**
     * 声明elasticsearch数据同步的队列
     * @return 返回队列
     */
    @Bean
    public Queue elasticsearchQueue(){
        return  new Queue(RabbitConstant.ES_QUEUE, true);
    }

    /**
     * 声明elasticsearch数据同步的交换机
     * @return 返回Direct模式的交换机
     */
    @Bean
    public DirectExchange elasticsearchExchange(){
        return  new DirectExchange(RabbitConstant.ES_EXCHANGE, true, false);
    }


    /**
     * 绑定elasticsearch数据同步的交换机和队列
     * @return Binding
     */
    @Bean
    public Binding elasticsearchBinding() {
        return BindingBuilder.bind(elasticsearchQueue()).to(elasticsearchExchange()).with(RabbitConstant.ES_ROUTING_KEY);
    }






    //-------------------------留言队列配置-------------------------------


    /**
     * 声明留言的队列
     * @return 返回队列
     */
    @Bean
    public Queue leavingAMessageQueue(){
        return  new Queue(RabbitConstant.LEAVING_A_MESSAGE_QUEUE, true);
    }

    /**
     * 声明留言的交换机
     * @return 返回Direct模式的交换机
     */
    @Bean
    public DirectExchange leavingAMessageExchange(){
        return  new DirectExchange(RabbitConstant.LEAVING_A_MESSAGE_EXCHANGE, true, false);
    }


    /**
     * 绑定留言的交换机和队列
     * @return Binding
     */
    @Bean
    public Binding leavingAMessageBinding() {
        return BindingBuilder.bind(leavingAMessageQueue()).to(leavingAMessageExchange()).with(RabbitConstant.LEAVING_A_MESSAGE_ROUTING_KEY);
    }





}
